/*
 * Copyright (C) 2012 gohminghui88
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package ezcms.dto;

import ezcms.constants.UserStatus;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author gohminghui88
 */
public class User implements Serializable {

    private long id;
    private String email;
    private String password;
    private List<Role> roles;
    private List<CreditCard> creditCards;
    private String title;
    private String firstName;
    private String lastName;
    private String handPhone;
    private String officePhone;
    private String homePhone;
    private String address;
    private String introduction;
    private FileResource avatar;
    private int status;

    public User() {
        this.status = UserStatus.VALID;
    }

    public User(String email, String password) {
        this();
        this.email = email;
        this.password = password;
    }

    public User(String email, String password, String introduction, List<Role> roles, List<CreditCard> creditCards, String title, String firstName, String lastName, String handPhone, String officePhone, String homePhone, String address, FileResource avatar) {
        this();
        this.email = email;
        this.password = password;
        this.introduction = introduction;
        this.roles = roles;
        this.creditCards = creditCards;
        this.title = title;
        this.firstName = firstName;
        this.lastName = lastName;
        this.handPhone = handPhone;
        this.officePhone = officePhone;
        this.homePhone = homePhone;
        this.address = address;
        this.avatar = avatar;
    }

    @Override
    public String toString() {
        return "User{" + "id=" + getId() + ", email=" + getEmail() + ", password=" + getPassword() + ", roles=" + getRoles() + ", title=" + getTitle() + ", firstName=" + getFirstName() + ", lastName=" + getLastName() + ", handPhone=" + getHandPhone() + ", officePhone=" + getOfficePhone() + ", homePhone=" + getHomePhone() + ", address=" + getAddress() + ", introduction=" + getIntroduction() + ", avatar=" + getAvatar() + '}';
    }

    public boolean hasRole(String roleName) {
        for (Role role : getRoles()) {
            if (role.getRoleName().equals(roleName)) {
                return true;
            }
        }
        return false;
    }

    /**
     * @return the id
     */
    public long getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(long id) {
        this.id = id;
    }

    /**
     * @return the email
     */
    public String getEmail() {
        return email;
    }

    /**
     * @param email the email to set
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }

    /**
     * @param password the password to set
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     * @return the roles
     */
    public List<Role> getRoles() {
        if (roles == null) {
            roles = new ArrayList<>();
        }
        return roles;
    }

    /**
     * @param roles the roles to set
     */
    public void setRoles(List<Role> roles) {
        this.roles = roles;
    }

    public List<CreditCard> getCreditCards() {
        return creditCards;
    }

    public void setCreditCards(List<CreditCard> creditCards) {
        this.creditCards = creditCards;
    }

    /**
     * @return the title
     */
    public String getTitle() {
        return title;
    }

    /**
     * @param title the title to set
     */
    public void setTitle(String title) {
        this.title = title;
    }

    /**
     * @return the firstName
     */
    public String getFirstName() {
        return firstName;
    }

    /**
     * @param firstName the firstName to set
     */
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    /**
     * @return the lastName
     */
    public String getLastName() {
        return lastName;
    }

    /**
     * @param lastName the lastName to set
     */
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    /**
     * @return the handPhone
     */
    public String getHandPhone() {
        return handPhone;
    }

    /**
     * @param handPhone the handPhone to set
     */
    public void setHandPhone(String handPhone) {
        this.handPhone = handPhone;
    }

    /**
     * @return the officePhone
     */
    public String getOfficePhone() {
        return officePhone;
    }

    /**
     * @param officePhone the officePhone to set
     */
    public void setOfficePhone(String officePhone) {
        this.officePhone = officePhone;
    }

    /**
     * @return the homePhone
     */
    public String getHomePhone() {
        return homePhone;
    }

    /**
     * @param homePhone the homePhone to set
     */
    public void setHomePhone(String homePhone) {
        this.homePhone = homePhone;
    }

    /**
     * @return the address
     */
    public String getAddress() {
        return address;
    }

    /**
     * @param address the address to set
     */
    public void setAddress(String address) {
        this.address = address;
    }

    /**
     * @return the introduction
     */
    public String getIntroduction() {
        return introduction;
    }

    /**
     * @param introduction the introduction to set
     */
    public void setIntroduction(String introduction) {
        this.introduction = introduction;
    }

    /**
     * @return the avatar
     */
    public FileResource getAvatar() {
        return avatar;
    }

    /**
     * @param avatar the avatar to set
     */
    public void setAvatar(FileResource avatar) {
        this.avatar = avatar;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }
}
